#!/usr/bin/env python
#-*- coding: utf-8 -*-

#_______________________ Simple As FucK Image Downloader _______________________
#
#                                by newfagpower


"""
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

    © 2011 newfagpower
    
"""

# TODO: multiligual support
# use GNU gettext and generate .mo files

import os
import sys
import optparse
import logging
log = logging.getLogger(__name__)

import ui
import data
import message

# FIXME: remove the info/control interaction and use managers
#        use multiprocessing instead of multithreading
#        UI BugFix

def process_options():
    usage = "usage: %prog [options]"
    version = "%prog 1.gamma"
    parser = optparse.OptionParser(usage=usage, version=version)
    parser.add_option("-d", dest="debug", default=False,
        help="run in debug mode", action="store_true")
    (opts, args) = parser.parse_args()
    if opts.debug:
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.INFO)
    
def create_working_dir():
    if not os.path.exists(data.WORKING_DIR):
        try:
            os.mkdir(data.WORKING_DIR)
        except:
            log.error(message.Fail.CANNOT_CREATE_WORKING_DIR)
            sys.exit(1)

if '__main__' == __name__:
    process_options()
    create_working_dir()
    app = ui.MainWindow()
    log.debug('running')
    app.run()

